import java.util.Arrays;

public class MyArrayList {
    public int[] elem;
    public int usedSize=0;
  public MyArrayList(){
      this.elem=new int[10]; //先初始化数组定义10个空间
  }
  public void add(int val){
      if(isFull()){
          this.elem=grow();
      }
      elem[usedSize]=val;
      usedSize++;
  }
  public void del(int index){
      if(isEmpty()||!isLegal(index)){
          return;
      }
     for(int i=index;i<usedSize-1;i++){
         elem[i]=elem[i+1];
     }
     usedSize--;
  }
  public boolean isLegal(int index){
      if(index<0||index>usedSize-1){
          return false;
      }
      return true;
  }
  public boolean isFull(){
     if(usedSize==this.elem.length){
        return true;
     }
     return false;
  }
  public int[] grow(){
      return Arrays.copyOf(elem,elem.length*2);
  }
  public boolean isEmpty(){
      if(usedSize==0){
          return true;
      }
      return false;
  }
  public int getData(int index){
      if(!isLegal(index)){
          return -1;
      }
      return elem[index];
  }
  public void del(){
      if(isEmpty()){
          return;
      }
      usedSize--;
  }
  public void add(int index,int val){

      if(!isLegal(index)){
          return;
      }
      if(isFull()){
          elem=grow();
      }
      for (int i = usedSize-1; i >=index; i++) {
          elem[i+1]=elem[i];
      }
      elem[index]=val;
      usedSize++;
  }
}
